package com.xinqi.utils.pool;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**normal
 * @author xin麒
 * @date 2023/8/12 15:13
 */
@Slf4j
@Component
public class MyJdkPool2 extends ThreadPoolExecutor {
//    @Value("${mypool.core-pool-size}")
//    private int corePoolSize;
//    @Value("${mypool.max-pool-size}")
//    private int maxPoolSize;
    public MyJdkPool2() {
        super(1, 2, 0, TimeUnit.SECONDS, new SynchronousQueue<>());
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        //这个是excute提交的时候
        if (t != null) {
            log.debug("afterExecute里面获取到excute提交的异常信息，处理异常" + t.getMessage());
            log.debug("print termination");
        }
/*        //如果r的实际类型是FutureTask 那么是submit提交的，所以可以在里面get到异常
        if (r instanceof FutureTask) {
            try {
                Future<?> future = (Future<?>) r;
                //get获取异常
                future.get();
            } catch (Exception e) {
                System.out.println("afterExecute里面获取到submit提交的异常信息，处理异常" + e);
            }
        }*/
    }
}
